package com.example.administrator.daydayappmarket.software.fragment;


import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.daydayappmarket.R;
import com.example.administrator.daydayappmarket.software.category.fragment.SWCategoryFragment;
import com.example.administrator.daydayappmarket.software.choice.fragment.SWChoiceFragment;
import com.example.administrator.daydayappmarket.software.fragment.adapter.ViewPagerFragmentAdapter;
import com.example.administrator.daydayappmarket.software.rating.fragment.SWRatingFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * A simple {@link Fragment} subclass.
 */
public class SoftwareFragment extends Fragment {
    int [] title={R.string.fragment_software_choice,R.string.fragment_software_rating,R.string.fragment_software_category};

    @InjectView(R.id.fragment_software_tabLayout)
    TabLayout fragmentSoftwareTabLayout;
    @InjectView(R.id.fragment_software_viewPager)
    ViewPager fragmentSoftwareViewPager;

    public SoftwareFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        View view = inflater.inflate(R.layout.fragment_software, container, false);
        ButterKnife.inject(this, view);
        List<Fragment> fragments=new ArrayList<>();
        fragments.add(new SWChoiceFragment());
        fragments.add(new SWRatingFragment());
        fragments.add(new SWCategoryFragment());


        List<String> titles=new ArrayList<>();
        titles.add(getResources().getString(R.string.fragment_software_choice));
        titles.add(getResources().getString(R.string.fragment_software_rating));
        titles.add(getResources().getString(R.string.fragment_software_category));


        ViewPagerFragmentAdapter adapter=new ViewPagerFragmentAdapter(getChildFragmentManager(),fragments,titles);
        fragmentSoftwareViewPager.setAdapter(adapter);
        fragmentSoftwareTabLayout.setupWithViewPager(fragmentSoftwareViewPager);

        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }
}
